/* ==============================================================================
 * 创 建 者：LYT
 * 创建日期：2018-03-14	
 * 功能描述：找回密码

 * 修 改 人:
 * 修改时间:
 * 修改描述：
 * ==============================================================================*/
//更改密码接口
var findPasswordUrl = baseUrl + 'DefaultF/ForgetPasswordForTel';
//图形验证码接口
var getValidateCode = baseUrl + 'common/GetValidateCode';

//手机验证码
var getCodeUrl = baseUrl + 'DefaultF/ForgetPasswordCode';

var vu;

$(function(){
	initVue();
})

function initVue(){
	vu = new Vue({
		el: '#forget',
		data: {
			ImageUrl: '',
			Name : '',
			Tel: '',
			newpassword: '',
			IdentifyingCode: '',
			VerifyCode: '',
			time: '',
			NewPassword: '',
			ConNewPassword: '',
			SecNewPassword : '',
			ConSecNewPassword : '',
			
			validCode: true,
			loadding : false,
			
			Code : '',
			codeImg : '',
		},
		mounted: function() {
			mui.init();
			this.getCode1();
		},
		methods: {
			getCode1: function () {
                common.post(getValidateCode, {},"", function (r) {
//              	console.log(r.Data.ImageUrl);
                    vu.codeImg = r.Data.ImageUrl;
                })
            },
			findPsdSubmit : function() {
				if(!this.Name) {
					mui.toast('请输入账号');
					return;
				}
				if(!this.Tel) {
					mui.toast('请输入手机号');
					return;
				}
				if(!this.IdentifyingCode) {
					mui.toast('请输入验证码');
					return;
				}
				if(!this.NewPassword) {
					mui.toast('请输入密码');
					return;
				}
				if(!this.ConNewPassword) {
					mui.toast('请再次输入密码');
					return;
				}
				if(this.NewPassword != this.ConNewPassword) {
					mui.toast('登录密码输入不一致');
					return;
				}
//				if(!this.SecNewPassword) {
//					mui.toast('请输入二级密码');
//					return;
//				}
//				if(!this.ConSecNewPassword) {
//					mui.toast('请再次输入二级密码');
//					return;
//				}
//				if(this.SecNewPassword != this.ConSecNewPassword) {
//					mui.toast('二级密码输入不一致');
//					return;
//				}
				this.loadding = true;
				common.post(findPasswordUrl, {
					UserName: this.Name,
					NewPassword: this.NewPassword,
					ConNewPassword: this.ConNewPassword,
					IdentifyingCode: this.IdentifyingCode,
//					SecNewPassword : this.SecNewPassword,
//					ConSecNewPassword : this.ConSecNewPassword,
				}, 'json', function(r) {
					vu.loadding = false;
					if(r.ErrorCode == 0) {
						mui.toast('密码修改成功');
						this.Tel = '';
						this.NewPassword = '';
						this.ConNewPassword = '';
						this.SecNewPassword = '';
						this.ConSecNewPassword = '';
					} else {
						mui.toast(r.ErrorMsg);
					}
				})
			},
			getCode : function(e) {
				var _this = this;
				var code = $(e.target);
				if(!this.Name) {
					mui.toast('请输入会员账号');
					return;
				} 
				if(!this.Tel) {
					mui.toast('请输入手机号');
					return;
				} 
				var time = 60;
				common.post(getCodeUrl, {Name: _this.Name,Tel: _this.Tel}, 'json', function(r) {
					if(r.ErrorCode == 0) {
						if(_this.validCode) {
							_this.validCode = false;
							if(r.Data.RemainingTime){
								time = r.Data.RemainingTime;
							}
							var t = setInterval(function() {
								time--;
								code.text(time + "秒");
								if(time == 0) {
									clearInterval(t);
									code.text("获取验证码");
									_this.validCode = true;
								}
							}, 1000)
						}
					} else {
						mui.toast(r.ErrorMsg);
					}
				})
			},
			//获取验证码
			getVerfication : function() {
				common.post(codeUrl, {}, 'json', function(r) {
					if(r.ErrorCode == 0) {
						vu.ImageUrl = r.Data.ImageUrl;
					} else {
						mui.toast(r.ErrorMsg);
					}
				})
			}
		}
	})
}
